const { DataTypes, Model } = require('sequelize');
const sequelize = require('../db/index.js');
class User extends Model {}

User.init({
    email: {
        type: DataTypes.STRING,
        allowNull: false
    },
    password: {
        type: DataTypes.STRING,
        allowNull: false
    },
    status: {
        type: DataTypes.ENUM('enabled', 'disabled'),
        allowNull: false,
        defaultValue: 'enabled',
    },
    membershipExpireAt: {
        type: DataTypes.DATE,
        allowNull: true, // 允许为空，表示非会员用户
    },
    // 邀请人id
    inviterId: {
        type: DataTypes.INTEGER,
        allowNull: true
    },
    // 观看到的视频页数
    page: {
        type: DataTypes.INTEGER,
        defaultValue: 1
    }
}, {
    sequelize,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    deletedAt: 'deleted_at',
    paranoid: true,
    defaultScope: {
        order: [['created_at', 'DESC']], // 设置默认排序
    },
});

User.belongsTo(User, { foreignKey: 'userId' })

module.exports = User;